<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/11/13
  Time: 9:33
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <title><spring:message code='usercenter.index.title' /></title>
    <link href="${path}/style/acg/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" media="screen" href="${path}/plugins/validate/validate.css">
    <script src="${path}/js/jquery.min.js" type="text/javascript"></script>
    <script src="${path}/plugins/validate/jquery.validate.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="${path}/js/ajaxfileupload.js"></script>
</head>
<body>
<jsp:include page="../public/header.jsp">
    <jsp:param    name="usercenter"    value="true"    />
</jsp:include>
<jsp:include page="../usercenter/leftMenu.jsp"></jsp:include>
<form id="frm">
<div class="member_box">
    <div class="member_title">
        <ul>
            <li class="hover"><a href=""><spring:message code='usercenter.proAdd.msg1' /></a></li>
            <li><a href=""><spring:message code='usercenter.proAdd.msg2' /></a></li>
        </ul>
    </div>
    <div class="member_account">
        <div class="member_form">
            <ul>
                <li class="clearfix">
                    <em style="color: #FF0000">请保证您上传的文件均为您的原创作品，如果上传非用户本人版权所有的作品或盗版作品而归类到“可出售”，被举报并核实后您会被要求作品下架和警告提醒，情节严重者可能会面临冻结账号或法律方面诉讼。</em>
                </li>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt><spring:message code='usercenter.proAdd.msg3' /></dt>
                        <dd>
                            <select class="select" name="firstClass" id="firstClass" onchange="f_findPajectType($(this).val(),'secondClass')">
                            </select>
                            <select class="select" name="secondClass" id="secondClass">
                            </select>
                        </dd>
                    </dl>
                </li>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt><spring:message code='usercenter.proAdd.msg4' /></dt>
                        <dd>
                            <select class="select" name="works_status" id="works_status">
                                <option value="117101"><spring:message code='usercenter.proAdd.msg5' /></option>
                                <option value="117102"><spring:message code='usercenter.proAdd.msg6' /></option>
                                <option value="117103"><spring:message code='usercenter.proAdd.msg7' /></option>
                            </select>
                        </dd>
                    </dl>
                </li>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt><spring:message code='usercenter.proAdd.msg8' /></dt>
                        <dd><input type="text" name="proName" id="proName" value="" class="txt660"></dd>
                    </dl>
                </li>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt><spring:message code='usercenter.proAdd.msg9' /></dt>
                        <dd><label for="fulAchievements" class="btn_addphto"><spring:message code='usercenter.proAdd.msg10' /></label>
                            <input style="display: none" type="file"  name="file" id="fulAchievements" onchange="f_file_upload()">
                            <input type="hidden" name="officialFileurl" id="officialFileurl" value="">
                        </dd>
                    </dl>
                </li>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt>&nbsp;</dt>
                        <dd>
                            <div class="sellshow">
                                <ul class="clearfix" id="showPic">

                                </ul>
                            </div>
                        </dd>
                    </dl>
                </li>
                <li class="clearfix" id="txtPrice">
                    <dl class="clearfix">
                        <dt><spring:message code='usercenter.proAdd.msg11' /></dt>
                        <dd><input type="text" name="price" id="price" value="" class="txt222"></dd>
                    </dl>
                </li>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt><spring:message code='usercenter.proAdd.msg12' /></dt>
                        <dd>
                            <textarea name="description2" id="description2" class="text650"></textarea>
                            <input type="hidden" name="description" id="description" value="">
                        </dd>
                    </dl>
                </li>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt>&nbsp;</dt>
                        <dd><input type="submit" id="" name="" value="<spring:message code='usercenter.proAdd.msg13' />" class="btn60"></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
</div>
    <input type="hidden" name="photoId" value="${photoId}">
</form>
<c:if test="${ sessionScope.language != 'en'}">
    <script src="${path}/plugins/validate/messages_cn.js" type="text/javascript"></script>
</c:if>
<!-- 文件上传JS -->
<script type="text/javascript">
    //上传图片
    //删除上传图片
    function deleteImg(num){
        //删除元素
        var url = $("#img"+num).attr("surl");
        $("#img"+num).remove();
        //为隐藏变量重新赋值
        var attachment = $("#attachment").val();
        var attachment2="";
        var indexa = attachment.indexOf(attachment);
        if(indexa != -1){
            var arr = attachment.split(",");
            if(arr.length >0 ){
                for(var i=0; i<arr.length; i++){
                    var tempobj = arr[i];
                    if(url == arr[i]){
                        arr.splice(i,1);
                    }
                }
            }
            console.log(arr);
            attachment2 = arr.join(",");
            $("#attachment").val(attachment2);
        }
    }
    var uploadnum = 1;
    function isImg(objId){
        var path = $("#"+objId).val();
        var pos2 = path.lastIndexOf(".");
        var result = path.substring(pos2);
        var imgs = ".bmp.jpg.dib.jpeg.png.jfif.jpe.tif.tiff.gif.BMP.JPG.DIB.JPEG.PNG.JFIF.JPE.TIF.TIFF.GIF";
        if(imgs.indexOf(result) > -1){
            return true;
        }else{
            return false;
        }
    }
    function f_file_upload(){
        //后缀验证
        if(!isImg("fulAchievements")){
            alert("请上传图片！");
            return;
        }

        $.ajaxFileUpload({
            url: '${path}/fileUpload/upload_resource_file.html',
            secureuri: false,
            fileElementId: 'fulAchievements',
            success: function (data) {
                //data = $.parseJSON(data);
                var data2 = data.split(",");
                var url = data2[0].replace(" ","");
                var fileName = data2[1].replace(" ","");
                var htmlStr  =  '<li id="img'+uploadnum+'">'+
                                '<img src="${path}/'+url+'" width="122" height="75">'+
                                '<span class="ico_del" onclick="deleteImg('+uploadnum+')">×</span>'+
                                '</li>';
                $("#showPic").append(htmlStr);
                if($("#officialFileurl").val() == ''){
                    $("#officialFileurl").val(url);
                }else{
                    $("#officialFileurl").val($("#officialFileurl").val()+","+url);
                }
                uploadnum++;
            },
            error:function(data){

                console.log("error");
                console.log(data);
            }
        });
    }

    /**级联查询分类*/
    function f_findPajectType(parent,selID){

        $.post("${path}/taskList/findTaskTypeByParent.html", { parent: parent},
                function(data, textStatus){

                    var html = "";
                    for (i in data) {

                        var type = data[i];
                        html += "<option value='" + type.id + "' skill='"+type.skill+"'>" + type.name + "</option>";
                    }

                    $("#"+selID).html(html);

                    if("secondClass" != selID){

                        f_findPajectType($("#"+selID).val(),"secondClass");
                    }
                });
    }


    $(function(){
        var validate = $("#frm").validate({
            rules : {
                proName : {
                    required: true
                },
                price : {
                    required: true,
                    number:true
                }

            },
            messages : {
                fulAchievements:{
                    required:"<spring:message code='usercenter.proAdd.msg14' />"
                }
            },
            success: function(label) {//验证成功添加样式
                label.html("&nbsp;").removeClass("checked").addClass("checked");
            },
            submitHandler : function(){
                $("#description").val($("#description2").val().replace(/\n/g,"<br/>"));
                $.post("${path}/usercenter/addProduct.html",
                        $("#frm").serialize()
                        ,function(data){
                            if(data.status == 1){
                                alert("<spring:message code='usercenter.proAdd.msg15' />");
                                window.location = "${path}/usercenter/getArtistProByPhotoId.html?photoId=${photoId}";
                            }else{
                                alert("<spring:message code='usercenter.proAdd.msg16' />");
                            }
                        },"json");
            }
        });
        f_findPajectType(1,"firstClass");
        //选择作品状态
        $("#works_status").change(function(){
            if($(this).val()==117102){
                $("#txtPrice").hide();
            }else{
                $("#txtPrice").show();
            }
        });
    });
</script>
<jsp:include page="../usercenter/leftMenuEnd.jsp"></jsp:include>
<jsp:include page="../public/footer.jsp"></jsp:include>
</body>
</html>
